package com.baidu.xiaosu.controller;

import com.baidu.xiaosu.bean.User;
import com.baidu.xiaosu.service.Demo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
public class DemoController {

    /*@Autowired
    private RestTemplate restTemplate;
    @Autowired
    private LoadBalancerClient loadBalancerClient;*/
    @Autowired
    private Demo demo;

    @RequestMapping("/hh/{id}")
    @HystrixCommand(fallbackMethod = "giao")
    public User getById(@PathVariable("id") String id){

/*        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        User forObject = this.demo.getById(id);
        return forObject;
    }

    public User giao(@PathVariable("id") String id){
        User user = new User();
        user.setName("错误");
        user.setPassword("错误");
        return user;
    }

    /*@RequestMapping("/getById/{id}")
    public User getById(@PathVariable("id") String id){

        User forObject = restTemplate.getForObject("http://provider:8080/user/getById/"+id, User.class);

        return forObject;
    }*/

}
